import strategies.*;
import core.*;

public class MainApp {

	/**
	 * @param args
	 */
	private static int integral(int elements_per_node, int nb_levels)
	{
		int nodes = 1;
		for (int i = 0 ; i < nb_levels ; i++)
			nodes += Math.pow(elements_per_node, (i+1));
		return nodes;
	}

	private static void benchmark_multiple_search(Tree tree, int element_to_find)
	{
		tree.change_strategy(new DepthFirstLeftToRightSearchStrategy());
		benchmark_search(tree, element_to_find);
		tree.change_strategy(new BreadthFirstLeftToRightSearchStrategy());
		benchmark_search(tree, element_to_find);
		tree.change_strategy(new DepthRightToLeftSearchStrategy());
		benchmark_search(tree, element_to_find);	
	}
	
	private static void benchmark_search(Tree tree, int element_to_find)
	{
		long start = System.currentTimeMillis();
		tree.find_element(element_to_find);
		long end = System.currentTimeMillis();
		System.out.println("[" + tree.print_search_strategy()  +"]\t Total time needed to find element "+ element_to_find + ": " + (end-start) + "ms");
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int nb_elements_per_node = 10;
		int nb_levels = 6;
		Tree tree = new Tree(nb_elements_per_node, nb_levels);
		int nb_nodes = Tree.get_nb_nodes();
		System.out.println("There are " + nb_nodes + " nodes instanciated and there should be " + integral(nb_elements_per_node, nb_levels) );
		benchmark_multiple_search(tree, Math.max( 1, 111112 ));
		benchmark_multiple_search(tree, Math.max( 1, (int)(nb_nodes * 0.88) ));
		benchmark_multiple_search(tree, nb_nodes-1);
		
	}

}
/*
0
1 12 23
2 3 4 5 6 7 8 9 10 11 | 13 14 15 16 17 18 19 20 21 22 |
*/
